package class03;

import class02.randoom.GenerateRandomArray;

import java.util.Arrays;
import java.util.Collections;

/**
 * @Auther: xw
 * @Create: 2022/3/4 16:01
 * @Description:
 */
public class MidFind {
    /**
     * 判断某个数是否存在数组中
     * @param arr
     * @param target
     * @return
     */
    public  static boolean find(int[] arr,int target){
        if (arr == null || arr.length <0)
            return false;
        int left = 0;
        int right = arr.length-1;

        while(left <= right){
            int middle = (left + right)/2;
            if(arr[middle] == target){
                return true;
            }else if(arr[middle] < target){
                left = middle +1;
            }else{
                right = middle -1;
            }
        }
        return false;
    }

    public static void main(String[] args) {
        //获取随机数组
        int[] array1 = GenerateRandomArray.getArray1(100, 50);
        Arrays.sort(array1);
        GenerateRandomArray.printArray(array1);
        System.out.println(find(array1,2));

    }
}
